<template>
	<div>
		<!-- 中间的主体部分 -->
		<form name="loginform">
			<div class="input-group" style="margin-top: 10px">
			  <span class="input-group-addon">邮&nbsp;箱</span>
			  <input type="text" class="form-control" placeholder="Email" v-model="email">
			</div>
			<div class="input-group" style="margin-top: 10px">
			  <span class="input-group-addon">用户名</span>
			  <input type="text" class="form-control" placeholder="UserName" v-model="username">
			</div>
			<input id="startDate" onfocus="WdatePicker()"/> 
   			<input id="endDate" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})"/> 
   			<a class="btn btn-info" v-on:click="dateTest()" style="width: 200px;margin-left: 53px;">时间测试</a>
			<div class="input-group" style="margin-top: 30px">
				<a class="btn btn-info" v-on:click="getPasswordPre()" style="width: 200px;margin-left: 53px;">发送</a>
			</div>
			<textarea class="form-control" rows="4" id="sendDatapack"></textarea>
			<a class="btn btn-info" v-on:click="sendPack()" style="cursor: default;">报文发送</a>
			<textarea class="form-control" rows="4" id="resultdatapack"></textarea>
		</form>
	
</template>

<script>
	Password.passwordPre = function() {
		return {
			data: function() {
				return {
					email: store.state.login.email,
					username: store.state.login.username 
				}
			},
			beforeRouteEnter: function(to, from, next) {
				console.log("login beforeRouteEnter. to: " + to);
				next(function(vm) {
					console.log(vm.$route);
				})
			},
			created: function() {
				console.log("login created.");
			},
			methods: {
				getPasswordPre: function() {
					checkPattern.checkEmail(this.email, "输入的邮箱格式不对！");
					checkNull.isNotEmpty(this.username, "输入的用户名不能为空！");
					console.log("email: " + this.email + ", password: " + this.password);
					var data = {
						"Email": this.email,
						"Username": this.username
					};
					this.$http.post('passwordAction/userPassword.action', data).then((response) => {
						if (response.body.returnCode == "000000") {
							var data = response.body.data;
							router.push("/register/registerResult");
						} else {
							toastr.info(response.body.errorMsg);
						}
					}, (response) => {
						toastr.info(response.body.errorMsg);
					})	 
					router.push("/register/registerConfirm"); 
				},
				dateTest: function() {
					var startDate = $("#startDate").val();
				    var endDate = $("#endDate").val();
					console.log("begin date: " + startDate + ", type: " + typeof endDate);
					console.log("end date: " + endDate);
				},
				sendPack: function() {
					var sendData = $("#sendDatapack").val();
					var data = {
						SendData: sendData
					}
					checkNull.isNotEmpty(sendData, "输入的发送报文不能为空！");
					this.$http.post('packageSend/sendPackage.action', data).then((response) => {
						if (response.body.returnCode == "000000") {
							var data = response.body.data;
							$("#resultdatapack").val(data.resultData)
						} else {
							toastr.info(response.body.errorMsg);
						}
					}, (response) => {
						toastr.info(response.body.errorMsg);
					})
				}
			}
		}
	}
</script>

<style>
	.login-btn {
		background-color: #FF0000;
	}
</style>